<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAgentRevenuesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('agent_revenues', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('agent_id')->index()->comment('代理商 ID');
            $table->tinyInteger('revenues_type')->default(1)->comment('收支类型; 1:收入 2:支出');
            $table->tinyInteger('type')->index()->comment('操作类型 见 Model 定义');
            $table->unsignedBigInteger('amount')->default(0)->comment('金额 (单位 分) 始终是正数 由收支类型决定意义');
            $table->bigInteger('balance')->default(0)->comment('此时的余额 (单位 分)');
            $table->bigInteger('unextractable_balance')->default(0)->comment('此时的不可提现余额 (单位 分)');

            $table->bigInteger('source_id')->default(0)->comment('来源 ID');
            $table->char('source_type', 64)->default('')->comment('来源类型');
            $table->index(['source_id', 'source_type']);

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('agent_revenues');
    }
}
